<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Class: EngineyardAPI::Engineyard</title>

  <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

  <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../lib/engineyard-api/engineyard_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/engineyard-api/engineyard.rb">lib/engineyard-api/engineyard.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link"><a href="../Object.html">Object</a></p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-c-new">::new</a></li>
          
          <li><a href="#method-i-account_by_id">#account_by_id</a></li>
          
          <li><a href="#method-i-account_by_name">#account_by_name</a></li>
          
          <li><a href="#method-i-environment_by_id">#environment_by_id</a></li>
          
          <li><a href="#method-i-environment_by_name">#environment_by_name</a></li>
          
          <li><a href="#method-i-environments">#environments</a></li>
          
          <li><a href="#method-i-reload">#reload</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
        
          <li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../EngineyardAPI.html">EngineyardAPI</a></li>
        
          <li><a href="../EngineyardAPI/Account.html">EngineyardAPI::Account</a></li>
        
          <li><a href="../EngineyardAPI/App.html">EngineyardAPI::App</a></li>
        
          <li><a href="../EngineyardAPI/Engineyard.html">EngineyardAPI::Engineyard</a></li>
        
          <li><a href="../EngineyardAPI/Environment.html">EngineyardAPI::Environment</a></li>
        
          <li><a href="../EngineyardAPI/Instance.html">EngineyardAPI::Instance</a></li>
        
          <li><a href="../Object.html">Object</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">EngineyardAPI::Engineyard</h1>

    <div id="description" class="description">
      
<p>Main class returned by <a
href="../EngineyardAPI.html#method-c-new">EngineyardAPI.new</a>(:key =&gt;
“key”)</p>

    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      
      <!-- Attributes -->
      <div id="attribute-method-details" class="method-section section">
        <h3 class="section-header">Attributes</h3>

        
        <div id="accounts-attribute-method" class="method-detail">
          <a name="accounts"></a>
          
          <a name="accounts="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">accounts</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
      </div><!-- attribute-method-details -->
      

      <!-- Methods -->
      
      <div id="public-class-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>

      
        <div id="new-method" class="method-detail ">
          <a name="method-c-new"></a>

          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">(options)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 15</span>
    <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>)  <span class="ruby-comment">#:nodoc</span>
          <span class="ruby-ivar">@accounts</span> = []
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;API key not specified. #{self.class}.new(:key =&gt; '&lt;api_key&gt;')&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-value">:key</span>
      <span class="ruby-ivar">@options</span>=<span class="ruby-identifier">options</span>
<span class="ruby-comment">#      @path = &quot;/environments/#{id}&quot;</span>
      <span class="ruby-ivar">@api</span> = <span class="ruby-constant">EngineyardAPI</span><span class="ruby-operator">::</span><span class="ruby-constant">EyAPI</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@options</span>[<span class="ruby-value">:key</span>])
      <span class="ruby-constant">EngineyardAPI</span>.<span class="ruby-identifier">const_set</span>(<span class="ruby-string">&quot;API&quot;</span>, <span class="ruby-ivar">@api</span>)
      <span class="ruby-identifier">reload</span>
    <span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>

          

          
        </div><!-- new-method -->

      
      </div><!-- public-class-method-details -->
    
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="account_by_id-method" class="method-detail ">
          <a name="method-i-account_by_id"></a>

          
          <div class="method-heading">
            <span class="method-name">account_by_id</span><span
              class="method-args">(id)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Find an account based on name.  Returns <a
href="Account.html">EngineyardAPI::Account</a></p>
            

            
            <div class="method-source-code" id="account_by_id-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">account_by_id</span>(<span class="ruby-identifier">id</span>)
      <span class="ruby-identifier">ac</span> = <span class="ruby-ivar">@accounts</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span> }
      <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;No such account&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">ac</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">ac</span>[<span class="ruby-value">0</span>]
<span class="ruby-keyword">end</span></pre>
            </div><!-- account_by_id-source -->
            
          </div>

          

          
        </div><!-- account_by_id-method -->

      
        <div id="account_by_name-method" class="method-detail ">
          <a name="method-i-account_by_name"></a>

          
          <div class="method-heading">
            <span class="method-name">account_by_name</span><span
              class="method-args">(name)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Locate an account by name.  Returns <a
href="Account.html">EngineyardAPI::Account</a></p>
            

            
            <div class="method-source-code" id="account_by_name-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">account_by_name</span>(<span class="ruby-identifier">name</span>)
      <span class="ruby-identifier">ac</span> = <span class="ruby-ivar">@accounts</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span> }
      <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;No such account&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">ac</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">ac</span>[<span class="ruby-value">0</span>]
<span class="ruby-keyword">end</span></pre>
            </div><!-- account_by_name-source -->
            
          </div>

          

          
        </div><!-- account_by_name-method -->

      
        <div id="environment_by_id-method" class="method-detail ">
          <a name="method-i-environment_by_id"></a>

          
          <div class="method-heading">
            <span class="method-name">environment_by_id</span><span
              class="method-args">(id)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Find an environment based on name.  Returns <a
href="Environment.html">EngineyardAPI::Environment</a></p>
            

            
            <div class="method-source-code" id="environment_by_id-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">environment_by_id</span>(<span class="ruby-identifier">id</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">environments</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">environment_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span> }.<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- environment_by_id-source -->
            
          </div>

          

          
        </div><!-- environment_by_id-method -->

      
        <div id="environment_by_name-method" class="method-detail ">
          <a name="method-i-environment_by_name"></a>

          
          <div class="method-heading">
            <span class="method-name">environment_by_name</span><span
              class="method-args">(name)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Find an environment based on name.  Returns <a
href="Environment.html">EngineyardAPI::Environment</a></p>
            

            
            <div class="method-source-code" id="environment_by_name-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">environment_by_name</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">environments</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span> }.<span class="ruby-identifier">first</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- environment_by_name-source -->
            
          </div>

          

          
        </div><!-- environment_by_name-method -->

      
        <div id="environments-method" class="method-detail ">
          <a name="method-i-environments"></a>

          
          <div class="method-heading">
            <span class="method-name">environments</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Returns array of environments</p>
            

            
            <div class="method-source-code" id="environments-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 37</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">environments</span>
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@accounts</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">account</span><span class="ruby-operator">|</span> <span class="ruby-identifier">account</span>.<span class="ruby-identifier">environments</span> }.<span class="ruby-identifier">flatten</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- environments-source -->
            
          </div>

          

          
        </div><!-- environments-method -->

      
        <div id="reload-method" class="method-detail ">
          <a name="method-i-reload"></a>

          
          <div class="method-heading">
            <span class="method-name">reload</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Call environment information from API. Information is cached in class until
reload is called again. Prevents calling API when not needed.</p>
            

            
            <div class="method-source-code" id="reload-source">
<pre>
<span class="ruby-comment"># File lib/engineyard-api/engineyard.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reload</span>
      <span class="ruby-identifier">account_list</span>=<span class="ruby-ivar">@api</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&quot;/accounts&quot;</span>)[<span class="ruby-string">'accounts'</span>]
  <span class="ruby-identifier">environment_list</span>=<span class="ruby-ivar">@api</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&quot;/environments&quot;</span>)[<span class="ruby-string">'environments'</span>]
  <span class="ruby-identifier">account_list</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@accounts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Account</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">a</span>) }
            <span class="ruby-identifier">environment_list</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
              <span class="ruby-identifier">account_by_id</span>(<span class="ruby-identifier">e</span>[<span class="ruby-string">'account'</span>][<span class="ruby-string">'id'</span>]).<span class="ruby-identifier">environments</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Environment</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">e</span>[<span class="ruby-string">'id'</span>],<span class="ruby-identifier">e</span>)  
            }
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- reload-source -->
            
          </div>

          

          
        </div><!-- reload-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

